package com.utc.teamcenter.common.app.dialog.bean;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

public abstract class BeanComponent {

	public static final int DEFAULT_LENGTH = 32;

	private String key;
	private String name;

	private JLabel label;

	public BeanComponent(String key, String name) {
		super();

		this.key = key;
		this.name = name;
		this.label = new JLabel(name + ":");
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public JLabel getLabel() {
		return label;
	}

	public void setLabel(JLabel label) {
		this.label = label;
	}

	public int addBeanToPanel(JPanel panel, int i) {
		panel.add(i + ".1.right.top", this.label);
		panel.add(i + ".2.left.top", this.getComponent());
		
		return i;
	}

	@Override
	public String toString() {
		return "BeanComponent [key=" + key + ", name=" + name + ", value="
				+ getText() + ", componentType="
				+ this.getClass().getSimpleName() + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		result = prime * result + ((label == null) ? 0 : label.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BeanComponent other = (BeanComponent) obj;
		if (key == null) {
			if (other.key != null)
				return false;
		} else if (!key.equals(other.key))
			return false;
		if (label == null) {
			if (other.label != null)
				return false;
		} else if (!label.equals(other.label))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	public abstract JComponent getComponent();

	public abstract String getText();

	public abstract boolean isRequired();

	public abstract void clear();

	public abstract void setText(String text);

	public abstract void setRequired(boolean required);

	public abstract void requestFocus();
	
	public abstract void setEnabled(boolean bool);
	
	public abstract void setVisible(boolean bool);
}
